#!/usr/bin/env python

import os
import time
import sys

HOUR = 60*60
DAY = HOUR*24
WEEK = DAY*7
YEAR = DAY*365

OUTDIR = 'old'

def main():
    if sys.argv[1:]:
        path = sys.argv[1]
    else:
        path = os.path.curdir

    now = time.time()

    for fname in os.listdir(path):
        if fname != OUTDIR and now-os.stat(fname).st_atime > WEEK:
            s = os.path.join(path,fname)
            d = os.path.join(path,OUTDIR,fname)

            if os.path.exists(d):
                i = 0
                while os.path.exists(d+'.'+str(i)):
                    i += 1
                d += '.'+str(i)
            #print s,d
            os.renames(s,d)

if __name__=='__main__':
    main()
